﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<!--/* 加载IE8兼容性片段 */-->
<head>
    <title>规则模板</title>
    <!--/* 加载全局样式 */-->
    <th:block th:replace="common/thinDecorator::globalStyle"></th:block>
    <!--/* 加载全局主题样式 */-->
    <th:block th:replace="common/thinDecorator::globalThemeStyle"></th:block>
    <!--/* 加载全局布局样式 */-->
    <th:block th:replace="common/thinDecorator::globalLayoutStyle"></th:block>
    <!--Axios请求-->
    <script th:src="@{/Vue/axios.min.js}" type="text/javascript" charset="utf-8"></script>
</head>

<body class="page-content-white page-container-bg-solid" style="overflow-x: hidden;">
<div class="page-wrapper">
    <!-- BEGIN CONTAINER -->
    <div class="page-container">
        <!-- BEGIN CONTENT -->
        <div class="page-content-wrapper">
            <!-- BEGIN CONTENT BODY -->
            <div class="page-content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="portlet light" style="margin-bottom: 0px;">
                            <div class="portlet-title">
                                <button type="button" class="btn btn-success " onclick="javascript:App.search();">
                                    搜索
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:App.reset();">
                                    重置
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:dataList.executeTask()">标准执行
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:dataList.refresh()">刷新
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:dataList.exportWord()">导出质量分析报告
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:dataList.createQuestForm()">生成质量问题工单
                                </button>
                            </div>
                            <div class="portlet-body">
                                <table id="table" style="width:100%;"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- END CONTENT BODY -->
        </div>
        <!-- END CONTENT -->
    </div>
</div>
<div id="scripts">
    <!--/* 加载IE8兼容性脚本 */-->
    <th:block th:replace="common/thinDecorator::IE8FixScripts"/>
    <!--/* 加载核心插件脚本 */-->
    <th:block th:replace="common/thinDecorator::corePluginsScripts"/>
    <!--/* 加载全局主题脚本 */-->
    <th:block th:replace="common/thinDecorator::globalThemeScripts"/>
    <!--/* 加载全局布局脚本 */-->
    <th:block th:replace="common/thinDecorator::globalLayoutScripts"/>
    <th:block th:replace="common/thinDecorator::globalsetupScripts"/>
    <!--Axios请求-->
    <script th:src="@{/Vue/axios.min.js}" type="text/javascript" charset="utf-8"></script>
    <script th:inline="javascript">
        $(function () {
            dataList.init();
        });
        var dataList = {
            easyuiTableInput: {},//记录查询框输入值
            //初始化
            init: function () {
                this.easyuiTableInput = localStorageManage.get("table", "searchForm");
                if (!this.easyuiTableInput) {
                    this.easyuiTableInput = {
                        searchData: {},
                        queryParams: {},
                    };
                } else {
                    //写form表单查询
                }
                var height = App.countHeight("table");
                console.log("height is " + height)
                this.createDataGrid();
            },
            createQuestForm:function () {
                let row = $("#table").datagrid("getSelections");
                if (row.length != 1) {
                    layer.msg("请有且选择一行标准创建问题工单", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                let projectId = row[0].id;
                axios.post('/qa/sqlTask/createQuestForm?projectId='+projectId, {}, {
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then(resp => {
                    if (resp.data.code == 200) {
                        /*科学防抖1分钟*/
                        layer.msg(resp.data.msg, {icon: 1, time: 2000, shift: 6});
                        layer.close(index);
                    } else {
                        layer.msg(resp.data.msg, {icon: 2, time: 2000, shift: 6});
                        layer.close(index);
                    }
                }).catch(error => {
                    console.log(error)
                });
            },
            exportWord:function () {
                let row = $("#table").datagrid("getSelections");
                if (row.length != 1) {
                    layer.msg("请有且选择一行数据导出", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                let projectId = row[0].id;
                axios.post('/qa/sqlTask/getSort?projectId='+projectId, {}, {
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then(resp => {
                    if (resp.data.code == 200) {
                        /*科学防抖1分钟*/
                        resp.data.data.forEach(item =>{
                            let url = "/qa/exportWord?projectId="+projectId+"&sort="+item;
                            window.open(url, "_blank");
                        })
                    } else {
                        layer.msg(resp.data.msg, {icon: 2, time: 2000, shift: 6});
                        layer.close(index);
                    }
                }).catch(error => {
                    console.log(error)
                });
            },
            refresh: function () {
                axios.post('/qa/sqlTask/refresh', {}, {
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then(resp => {
                    if (resp.data.code == 200) {
                        /*科学防抖1分钟*/
                        layer.msg(resp.data.msg, {icon: 1, time: 1000, shift: 6});
                        layer.close(index);
                        $("#table").datagrid("reload");
                    } else {
                        layer.msg(resp.data.msg, {icon: 2, time: 2000, shift: 6});
                        layer.close(index);
                    }
                }).catch(error => {
                    console.log(error)
                });
            },
            executeTask: function () {
                let row = $("#table").datagrid("getSelections");
                if (row.length != 1) {
                    layer.msg("请有且选择一行数据编辑", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                axios.post('/qa/sqlTask/runTask?parentId=' + row[0].id, {}, {
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then(resp => {
                    if (resp.data.code == 200) {
                        /*执行任务并刷新表格*/
                        layer.msg(resp.data.msg, {icon: 1, time: 1000, shift: 6});
                        layer.close(index);
                        $("#table").datagrid("reload");
                    }
                }).catch(error => {
                    console.log(error)
                });

            },
            updateInfo: function () {
                var row = $("#table").datagrid("getSelections");
                if (row.length != 1) {
                    layer.msg("请有且选择一行数据编辑", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                window.location.href = "/qa/ruleModel/detail?id=" + row[0].id;
            },
            deleteByInfo: function () {
                var row = $("#table").datagrid("getSelections");
                if (row.length < 1) {
                    layer.msg("请至少选择一行数据", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                layer.confirm('确定删除吗？', {
                        title: '删除操作',
                        icon: 3,
                        area: ['340px', '160px'], //弹框的大小
                        btn: ['确定', '取消'] //按钮
                    }, function (index) {
                        //点击“确定”执行的操作
                        var ids = [];
                        for (var i = 0; i < row.length; i++) {
                            ids.push(row[i].id);
                        }
                        $.ajax({
                            url: "/qa/ruleModel/remove",
                            type: "post",
                            data: {
                                ids: ids.join(",")
                            }
                        }, function (result) {
                            layer.msg(result.msg);
                        }, "json");
                        layer.close(index);
                        $("#table").datagrid("reload");
                    }, function () {
                        //点击“取消”执行的操作
                        layer.close();
                    }
                )
            },
            //创建datagrid
            createDataGrid: function () {
                $("#table").datagrid({
                    url: "/qa/sqlTask/getParentId/datagrid",
                    height: App.getPortletInnerHeight(),
                    queryParams: this.easyuiTableInput.queryParams,
                    frozenColumns: [
                        [
                            {field: 'checkbox', checkbox: true, align: "center", width: 35,},
                            {
                                field: 'number',
                                title: '序号',
                                align: "center",
                                width: 35,
                                formatter: function (data, row, index) {
                                    return index + 1;
                                }
                            },
                        ]
                    ],
                    columns: [
                        [

                            {
                                "field": "cnName", title: "数据质量标准名称", width: 200, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "syfw", title: "适用范围", width: 100, sortable: false,
                                formatter: function (data, row, index) {

                                    return data;
                                }
                            },
                            {
                                "field": "sjzllx", title: "数据质量类型", width: 80, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "createUser", title: "创建人", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "createTime", title: "创建时间", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "modifyTime", title: "发布时间", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "ckwx", title: "参考文献", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "sjzlbzml", title: "数据质量标准目录", width: 100, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "fbzt", title: "发布状态", width: 100, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            }
                        ]
                    ],
                    fitColumns: false,//自适应
                    remoteFilter: true,
                    remoteSort: true,
                    clientPaging: false,
                    singleSelect: false,//单选
                    checkOnSelect: true,
                    striped: true, //表格设置为条纹
                    emptyMsg: "表中数据为空",
                    pagination: true,//分页
                    pagePosition: "bottom",
                    pageList: [20, 50, 100],
                    pageSize: 20,
                    automaticPolling: false,
                    view: detailview,
                    detailFormatter: function (index, row) {
                        return '<div style="padding:5px"><table id="tableSon-' + index + '"></table></div>';
                    },
                    onDblClickRow: function (rowIndex, row) {
                    },
                    onExpandRow: function (index, row) {
                        $('#tableSon-' + index).datagrid({
                            url: '/qa/sqlTask/byParentId/datagrid?parentId=' + row.id,
                            fitColumns: false,//自适应
                            remoteFilter: true,
                            remoteSort: true,
                            clientPaging: false,
                            singleSelect: false,//单选
                            checkOnSelect: true,
                            striped: true, //表格设置为条纹
                            emptyMsg: "表中数据为空",
                            automaticPolling: false,
                            height: 'auto',
                            columns: [
                                [
                                    {field: 'beginTime', title: '开始时间', width: 150},
                                    {field: 'endTime', title: '结束时间', width: 150},
                                    {
                                        field: 'executeTime', title: '耗时(s)', width: 100,
                                        formatter: function (data, row, index) {
                                            if (data) {
                                                return Number.parseInt(data) / 1000;
                                            }
                                            return '---';
                                        }
                                    },
                                    {field: 'total', title: '执行规则数', width: 100},
                                    {
                                        field: 'suctol', title: '执行通过数', width: 100,
                                        formatter: function (data, row, index) {
                                            if (data) {
                                                return data;
                                            }
                                            return 0;
                                        }
                                    },
                                    {
                                        field: 'nottal',
                                        title: '执行未通过数',
                                        width: 100,
                                        formatter: function (data, row, index) {
                                            if (data) {
                                                return data;
                                            }
                                            return 0;
                                        }
                                    },
                                    {field: 'executeStatus', title: '执行状态', width: 120},
                                    {
                                        field: 'MGSCC', title: '操作', width: 120,
                                        formatter: function (data, row, index) {
                                            if (row.executeStatus != '执行成功'){
                                                return "<a href='javascript:void(0)' onclick='dataList.showNoDetail("  + row.projectId+","+row.sort + ")'>查看</a>";
                                            }
                                            return "<a href='javascript:void(0)' onclick='dataList.showDetail(" + row.projectId+","+row.sort + ")'>查看</a>";
                                        }
                                    },
                                ]
                            ],
                            onResize: function () {
                                $('#table').datagrid('fixDetailRowHeight', index);
                            },
                            onLoadSuccess: function () {
                                setTimeout(function () {
                                    $('#table').datagrid('fixDetailRowHeight', index);
                                }, 0);
                            }
                        });
                        $('#table').datagrid('fixDetailRowHeight', index);
                    }

                });
                this.createFilter();
            },
            showDetail: function (projectId,sort) {
                // 获取详情弹窗显示
                layer.open({
                    type: 2,
                    title: '执行记录详情',
                    id: 'layui-layer-rule',
                    area: ['65%', '80%'],
                    content: "/qa/sqlTask/taskInfoView?projectId=" + projectId+"&sort="+sort,
                    success: function (layero) {

                    }
                });
            },
            showNoDetail:function (index) {
                layer.msg('执行的任务未完成!请耐心等待', {icon: 2, time: 2000, shift: 6});
                return false;
            },
            //模糊查询
            createFilter: function () {
                $('#table').datagrid('enableFilter', [
                    {"field": "number", type: 'label',},
                    {
                        "field": "cnName", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.cnName,
                        }
                    },
                    {
                        "field": "syfw", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.syfw,
                        }
                    },
                    {
                        "field": "sjzllx", type: 'combobox', options: {
                            valueField: 'code',
                            textField: 'name',
                            editable: false,
                            data: [{code: '数据模型标准', name: '数据模型标准'}, {
                                code: '数据编码标准',
                                name: '数据编码标准'
                            }, {code: '主数据接口标准', name: '主数据接口标准'}],
                            value: dataList.easyuiTableInput.searchData.sjzllx,
                        }
                    },
                    {
                        "field": "createUser", type: 'label', options: {
                            value: dataList.easyuiTableInput.searchData.createUser,
                        }
                    },
                    {
                        "field": "createTime", type: 'label', options: {
                            value: dataList.easyuiTableInput.searchData.createTime,
                        }
                    },
                    {
                        "field": "modifyTime", type: 'label', options: {
                            value: dataList.easyuiTableInput.searchData.createTime,
                        }
                    },
                    {
                        "field": "ckwx", type: 'label', options: {
                            value: dataList.easyuiTableInput.searchData.ckwx,
                        }
                    },
                    {
                        "field": "sjzlbzml", type: 'label', options: {
                            value: dataList.easyuiTableInput.searchData.sjzlbzml,
                        }
                    },
                    {
                        "field": "fbzt", type: 'label', options: {
                            valueField: 'code',
                            textField: 'name',
                            editable: false,
                            data: [{code: '已发布', name: '已发布'}, {code: '未发布', name: '未发布'}, {
                                code: '发布中',
                                name: '发布中'
                            }, {code: '已驳回', name: '已驳回'}],
                            value: dataList.easyuiTableInput.searchData.fbzt,
                        }
                    },
                ]);
                var searchBtn = '<a class="table-action" style="margin-left: 1px" onclick="App.search()">查询</a>';
                $('.datagrid-filter-row td[field="number"]').html(searchBtn);
            },
            edit: function () {
                var row = $("#table").datagrid("getSelected");
                if (0 !== row.stateId) {
                    layer.msg("该数据无法编辑", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                layer.msg("该数据无法编辑", {icon: 2, time: 1000, shift: 6});
            },
            back: function () {
                layer.msg("该数据无法编辑", {icon: 2, time: 1000, shift: 6});
            },
        };
    </script>
</div>
<!-- END CONTAINER -->
</body>

</html>